﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualTournaments.Business.Tournaments;

namespace VirtualTournaments.Business.Bets
{
	public class TournamentPodiumBetType : BetType
	{
		private Tournament _tournament;

		
		public TournamentPodiumBetType(Tournament tournament)
			: base(tournament)
		{
			_tournament = tournament;
		}

		protected override BetTarget[] CreateAllAvaliableBetTargets(ICompetition competition)
		{
			List<BetTarget> betTargetCollection = new List<BetTarget>();

			Position[] positionArray = new Position[]
            {
                Position.First,
                Position.Second,
                Position.Third
            };

			foreach (var team in ((Tournament)competition).Teams)
			{
				foreach (var position in positionArray)
				{
					betTargetCollection.Add(new TournamentSimplePositionBetTarget((Tournament)competition, (Team)team, position));
				}

			}
			return betTargetCollection.ToArray();
		}
		public BetTarget getResultByWinningSimplePosition(String teamName, Position position)
		{
			foreach (var item in this.BetTargets)
			{
				if (((TournamentSimplePositionBetTarget)item).team.Name.ToUpper() == teamName.ToUpper() &&
					((TournamentSimplePositionBetTarget)item).position == position)
					return ((TournamentSimplePositionBetTarget)item);
			}
			return null;
		}

		
	}
}
